﻿using System;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class PlayerSkillMoveCommand : PlayerCommand
    {
        public Vector2 dir = Vector2.zero;
        public int skillID { get; private set; }

        public override EPlayerCommandType type => EPlayerCommandType.Skill;

        public void Initialize(Vector2 dir, int nSkillID)
        {
            this.skillID = nSkillID;
            this.dir = dir;
        }

        public override void Execute(UnitView entity)
        {
            var rOrderComp = entity.GetComponent<PlayerOrderComponent>(ETComponentType.PlayerOrderComponent);
            rOrderComp.SkillMove(this.skillID, this.dir);
        }

        public override void OnReset()
        {
            base.OnReset();
            this.skillID = 0;
            this.dir = Vector2.zero;
        }

        public override void Free()
        {
            ClassPool.Put(this);
        }
    }
}